﻿using System;
using System.Data;
using System.Text;
using MySql.Data.MySqlClient;
using Maticsoft.DBUtility;//Please add references
namespace becom.DAL
{
	/// <summary>
	/// 数据访问类:oa_contact
	/// </summary>
	public partial class oa_contact
	{
		public oa_contact()
		{}
		#region  Method

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(string LoginID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from oa_contact");
			strSql.Append(" where LoginID=@LoginID ");
			MySqlParameter[] parameters = {
					new MySqlParameter("@LoginID", MySqlDbType.VarChar,10)};
			parameters[0].Value = LoginID;

			return DbHelperMySQL.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public void Add(becom.Model.oa_contact model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into oa_contact(");
			strSql.Append("LoginID,LoginCode,GroupCode,GroupName,Name,Sex,Political,OrderNum,CreateDate)");
			strSql.Append(" values (");
			strSql.Append("@LoginID,@LoginCode,@GroupCode,@GroupName,@Name,@Sex,@Political,@OrderNum,@CreateDate)");
			MySqlParameter[] parameters = {
					new MySqlParameter("@LoginID", MySqlDbType.VarChar,10),
					new MySqlParameter("@LoginCode", MySqlDbType.VarChar,20),
					new MySqlParameter("@GroupCode", MySqlDbType.VarChar,10),
					new MySqlParameter("@GroupName", MySqlDbType.VarChar,20),
					new MySqlParameter("@Name", MySqlDbType.VarChar,10),
					new MySqlParameter("@Sex", MySqlDbType.Int32,11),
					new MySqlParameter("@Political", MySqlDbType.VarChar,20),
					new MySqlParameter("@OrderNum", MySqlDbType.Int32,11),
					new MySqlParameter("@CreateDate", MySqlDbType.DateTime)};
			parameters[0].Value = model.LoginID;
			parameters[1].Value = model.LoginCode;
			parameters[2].Value = model.GroupCode;
			parameters[3].Value = model.GroupName;
			parameters[4].Value = model.Name;
			parameters[5].Value = model.Sex;
			parameters[6].Value = model.Political;
			parameters[7].Value = model.OrderNum;
			parameters[8].Value = model.CreateDate;

			DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(becom.Model.oa_contact model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update oa_contact set ");
			strSql.Append("LoginCode=@LoginCode,");
			strSql.Append("GroupCode=@GroupCode,");
			strSql.Append("GroupName=@GroupName,");
			strSql.Append("Name=@Name,");
			strSql.Append("Sex=@Sex,");
			strSql.Append("Political=@Political,");
			strSql.Append("OrderNum=@OrderNum,");
			strSql.Append("CreateDate=@CreateDate");
			strSql.Append(" where LoginID=@LoginID ");
			MySqlParameter[] parameters = {
					new MySqlParameter("@LoginCode", MySqlDbType.VarChar,20),
					new MySqlParameter("@GroupCode", MySqlDbType.VarChar,10),
					new MySqlParameter("@GroupName", MySqlDbType.VarChar,20),
					new MySqlParameter("@Name", MySqlDbType.VarChar,10),
					new MySqlParameter("@Sex", MySqlDbType.Int32,11),
					new MySqlParameter("@Political", MySqlDbType.VarChar,20),
					new MySqlParameter("@OrderNum", MySqlDbType.Int32,11),
					new MySqlParameter("@CreateDate", MySqlDbType.DateTime),
					new MySqlParameter("@LoginID", MySqlDbType.VarChar,10)};
			parameters[0].Value = model.LoginCode;
			parameters[1].Value = model.GroupCode;
			parameters[2].Value = model.GroupName;
			parameters[3].Value = model.Name;
			parameters[4].Value = model.Sex;
			parameters[5].Value = model.Political;
			parameters[6].Value = model.OrderNum;
			parameters[7].Value = model.CreateDate;
			parameters[8].Value = model.LoginID;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(string LoginID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from oa_contact ");
			strSql.Append(" where LoginID=@LoginID ");
			MySqlParameter[] parameters = {
					new MySqlParameter("@LoginID", MySqlDbType.VarChar,10)};
			parameters[0].Value = LoginID;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string LoginIDlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from oa_contact ");
			strSql.Append(" where LoginID in ("+LoginIDlist + ")  ");
			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public becom.Model.oa_contact GetModel(string LoginID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select LoginID,LoginCode,GroupCode,GroupName,Name,Sex,Political,OrderNum,CreateDate from oa_contact ");
			strSql.Append(" where LoginID=@LoginID ");
			MySqlParameter[] parameters = {
					new MySqlParameter("@LoginID", MySqlDbType.VarChar,10)};
			parameters[0].Value = LoginID;

			becom.Model.oa_contact model=new becom.Model.oa_contact();
			DataSet ds=DbHelperMySQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["LoginID"]!=null && ds.Tables[0].Rows[0]["LoginID"].ToString()!="")
				{
					model.LoginID=ds.Tables[0].Rows[0]["LoginID"].ToString();
				}
				if(ds.Tables[0].Rows[0]["LoginCode"]!=null && ds.Tables[0].Rows[0]["LoginCode"].ToString()!="")
				{
					model.LoginCode=ds.Tables[0].Rows[0]["LoginCode"].ToString();
				}
				if(ds.Tables[0].Rows[0]["GroupCode"]!=null && ds.Tables[0].Rows[0]["GroupCode"].ToString()!="")
				{
					model.GroupCode=ds.Tables[0].Rows[0]["GroupCode"].ToString();
				}
				if(ds.Tables[0].Rows[0]["GroupName"]!=null && ds.Tables[0].Rows[0]["GroupName"].ToString()!="")
				{
					model.GroupName=ds.Tables[0].Rows[0]["GroupName"].ToString();
				}
				if(ds.Tables[0].Rows[0]["Name"]!=null && ds.Tables[0].Rows[0]["Name"].ToString()!="")
				{
					model.Name=ds.Tables[0].Rows[0]["Name"].ToString();
				}
				if(ds.Tables[0].Rows[0]["Sex"]!=null && ds.Tables[0].Rows[0]["Sex"].ToString()!="")
				{
					model.Sex=int.Parse(ds.Tables[0].Rows[0]["Sex"].ToString());
				}
				if(ds.Tables[0].Rows[0]["Political"]!=null && ds.Tables[0].Rows[0]["Political"].ToString()!="")
				{
					model.Political=ds.Tables[0].Rows[0]["Political"].ToString();
				}
				if(ds.Tables[0].Rows[0]["OrderNum"]!=null && ds.Tables[0].Rows[0]["OrderNum"].ToString()!="")
				{
					model.OrderNum=int.Parse(ds.Tables[0].Rows[0]["OrderNum"].ToString());
				}
				if(ds.Tables[0].Rows[0]["CreateDate"]!=null && ds.Tables[0].Rows[0]["CreateDate"].ToString()!="")
				{
					model.CreateDate=DateTime.Parse(ds.Tables[0].Rows[0]["CreateDate"].ToString());
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select LoginID,LoginCode,GroupCode,GroupName,Name,Sex,Political,OrderNum,CreateDate ");
			strSql.Append(" FROM oa_contact ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperMySQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			MySqlParameter[] parameters = {
					new MySqlParameter("@tblName", MySqlDbType.VarChar, 255),
					new MySqlParameter("@fldName", MySqlDbType.VarChar, 255),
					new MySqlParameter("@PageSize", MySqlDbType.Int32),
					new MySqlParameter("@PageIndex", MySqlDbType.Int32),
					new MySqlParameter("@IsReCount", MySqlDbType.Bit),
					new MySqlParameter("@OrderType", MySqlDbType.Bit),
					new MySqlParameter("@strWhere", MySqlDbType.VarChar,1000),
					};
			parameters[0].Value = "oa_contact";
			parameters[1].Value = "LoginID";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperMySQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  Method
	}
}

